package io;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class ReadStringDemo {
    public static void main(String[] args) throws IOException {

        File file = new File("src/main/java/io/ReadStringDemo.java");
        FileInputStream fis = new FileInputStream(file);
        //获取长度
        long len = file.length();
        //创建接收器--byte数组
        byte[] date = new byte[(int)len];
        int a =fis.read(date);//  a  的返回值是len的长度
//        System.out.println("read()的返回值a  ："+a + len);
        //创建字符串----转换byte为字符串输出
        String str = new String(date, StandardCharsets.UTF_8);
        System.out.println(str  );
        fis.close();

    }
}
